//
//  FindTableViewCell.m
//  项目三
//
//  Created by rimi1 on 2016/12/9.
//  Copyright © 2016年 Wangxingqian. All rights reserved.
//

#import "FindTableViewCell.h"

static NSInteger spacing_ = 20;

@implementation FindTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.img];
        [self.img addSubview:self.maskView];
        [self.img addSubview:self.headImage];
        [self.img addSubview:self.userName];
        [self.img addSubview:self.menuName];
        [self.img addSubview:self.food];
    }
    return self;
}

#pragma mark - respondsTo..

- (void)respondsToHead:(UITapGestureRecognizer *)gesture {
    [self.delegate findTableViewCell:self tapOfHead:gesture];
}

#pragma mark - get

- (UIImageView *)img {
    
    if (!_img) {
        
        _img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWIDTH, WXQAdaptionHeight(230))];
        _img.layer.shadowOpacity = 0.15;
        _img.layer.shadowOffset = CGSizeMake(0, 10);
        _img.userInteractionEnabled = YES;
        
    }
    return _img;
}

- (UIView *)maskView {
    
    if (!_maskView) {
        
        _maskView = [[UIView alloc] initWithFrame:self.img.bounds];
        _maskView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
        
    }
    return _maskView;
}

- (UIImageView *)headImage {
    
    if (!_headImage) {
        
        CGFloat diameter = WXQAdaptionHeight(40);
        _headImage = [[UIImageView alloc] initWithFrame:CGRectMake(spacing_, spacing_, diameter, diameter)];
        _headImage.layer.cornerRadius = diameter/2;
        _headImage.layer.masksToBounds = YES;
        _headImage.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(respondsToHead:)];
        [_headImage addGestureRecognizer:tap];
        
    }
    return _headImage;
}

- (UILabel *)userName {
    
    if (!_userName) {
        
        CGFloat x = CGRectGetMaxX(self.headImage.frame) + spacing_/2;
        _userName = [[UILabel alloc] initWithFrame:CGRectMake(x, CGRectGetMinY(self.headImage.frame), kWIDTH - x - spacing_/2, CGRectGetHeight(self.headImage.bounds))];
        _userName.font = [UIFont systemFontOfSize:WXQAdaptionHeight(14)];
        _userName.textColor = [UIColor whiteColor];
        
    }
    return _userName;
}

- (UILabel *)menuName {
    
    if (!_menuName) {
        
        CGFloat height = WXQAdaptionHeight(18);
        _menuName = [[UILabel alloc] initWithFrame:CGRectMake(spacing_, CGRectGetMinY(self.food.frame) - height - spacing_/2, kWIDTH - spacing_ * 2, height)];
        _menuName.font = [UIFont boldSystemFontOfSize:height];
        _menuName.textAlignment = NSTextAlignmentCenter;
        _menuName.textColor = [UIColor whiteColor];
        
    }
    return _menuName;
}

- (UILabel *)food {
    
    if (!_food) {
        
        CGFloat height = WXQAdaptionHeight(16);
        _food = [[UILabel alloc] initWithFrame:CGRectMake(spacing_, CGRectGetHeight(self.img.bounds) - height - spacing_/2, kWIDTH - 2 * spacing_, height)];
        _food.font = [UIFont systemFontOfSize:height];
        _food.textAlignment = NSTextAlignmentCenter;
        _food.textColor = [UIColor whiteColor];
        
    }
    return _food;
}

@end














